package com.dxl.service.optlog;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dxl.bean.session.Session;
import com.dxl.common.annotation.RequirePermission;
import com.dxl.common.utils.Utils;
import com.dxl.dao.common.context.SessionContext;
import com.dxl.entity.account.Account;
import com.dxl.entity.optlog.OptLog;
import com.dxl.service.common.BaseService;

@Service
@Transactional
public class OptLogService extends BaseService {
	private static final Logger LOG = Logger.getLogger(OptLogService.class);
	
	public void addLog(RequirePermission rp) {
		if (Utils.isNull(rp)) {
			return;
		}
		OptLog log = new OptLog();
		Session session = SessionContext.getSession();
		if (Utils.isNotNull(session)) {
			Account acct = session.getAccount();
			if (Utils.isNotNull(acct)) {
				log.setAccountId(acct.getId());
			}
			log.setIp(session.getIp());
		}
		log.setFnCode(Utils.join(rp.value(), ","));
		log.setFnName(rp.name());
		log.setFnDesc(rp.desc());
		this.save(log);
	}
}
